package top.abrsm.config;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import top.abrsm.entity.OrderEntity;
import top.abrsm.entity.UserEntity;
import top.abrsm.entity.bo.PushBuyMessageBo;
import top.abrsm.service.IUserService;
import top.abrsm.util.CommonUtil;
import top.abrsm.util.PushMessageUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 0:21 2023-11-21
 * @return
 */
@Component
public class PushMessage {

    @Resource
    private IUserService iUserService;

    /**
     * 微信小程序购书成功后消息通知
     * {{first.DATA}}
     * 任务名称：{{keyword1.DATA}}
     * 开始时间：{{keyword2.DATA}}
     * 结束时间：{{keyword3.DATA}}
     * 处理结果：{{keyword4.DATA}}
     * {{remark.DATA}}
     * @param orderEntity
     */
    public void sendBuy (OrderEntity orderEntity) {
        String nowDate = CommonUtil.getFormatDateTime ( "yyyy-MM-dd HH:mm:ss " );
        PushBuyMessageBo pushBuyMessageBo = new PushBuyMessageBo ( "您好，您有新采购需处理。", orderEntity.getOutTradeNo (), nowDate, nowDate, "完成", "感谢您的查阅，按及时处理。" );
        UserEntity userEntity = new UserEntity ();
        List<UserEntity> userEntities = iUserService.queryList ( userEntity );
        for ( UserEntity u : userEntities ) {
            if ( StringUtils.isNotBlank ( u.getPubOpenId () ) ) {
                PushMessageUtil.pushBuyMessage ( u.getPubOpenId (), "Ucd7JdVZIC3rw-vzjvGH8rqr3JJuZ0_PD3AzpNr4Qs4", pushBuyMessageBo );
            }
        }
    }

}
